package com.coolw.data.migrate.controller;

import com.coolw.data.migrate.domain.request.DataMigrateRequest;
import com.coolw.data.migrate.domain.response.DataMigrateResponse;
import com.coolw.data.migrate.process.DataMigrateSimpleProcess;
import com.coolw.data.migrate.process.strategy.DataMigrateContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 数据迁移控制层
 *
 * @author coolw
 * @date 2024/2/5 16:14
 */
@Slf4j
@RestController
@RequestMapping("/data-migrate")
public class DataMigrateController {

    @Resource
    private DataMigrateSimpleProcess dataMigrateSimpleProcess;

    @Resource
    private DataMigrateContext dataMigrateContext;

    /**
     * 数据迁移
     *
     * @param request 数据迁移条件
     * @return 数据迁移结果
     */
    @PostMapping("/v1/process")
    public DataMigrateResponse process1(@Validated @RequestBody DataMigrateRequest request) {
        DataMigrateResponse response = dataMigrateSimpleProcess.process(request);
        log.info("数据迁移结果:{}", response);
        return response;
    }

    /**
     * 数据迁移
     *
     * @param request 数据迁移条件
     * @return 数据迁移结果
     */
    @PostMapping("/v2/process")
    public DataMigrateResponse process2(@Validated @RequestBody DataMigrateRequest request) {
        DataMigrateResponse response = dataMigrateContext.getProcess(request.getMigrateType()).process(request);
        log.info("数据迁移结果:{}", response);
        return response;
    }
}
